# Python 2.6.4
# Project Euler, Problem 47
# Copyright 2010 Talha Zaman

def sievefactors(limit):
    sieve = [0 for i in range(0, limit)]
    sieve[0] = sieve[1] = 1
    for i in range(2,limit):
        if sieve[i]: continue
        for j in range(2*i, limit, i):
            sieve[j] += 1
    return sieve

lim = 1000000
distinct = 4
sieve = sievefactors(lim)
for i in range(2,lim-distinct):
    if all([sieve[j]==distinct for j in range(i,i+distinct)]):
        print i
        break
